package com.orangesoft.common.vo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.io.Serializable;

/**
 * --> 返回响应的参数对象
 *
 * @author xhy
 */
@JsonIgnoreProperties({"extendData"})
public class ResultDTO implements Serializable {
    /**
     * 返回代码 0成功 1失败
     */
    private Integer ret;
    /**
     * 返回提示信息
     */
    private Integer errorCode;
    /**
     * 接口响应的数据对象
     */
    private Object data;
    /**
     * 描述
     */
    private String msg;

    public ResultDTO(Integer ret, Integer errorCode, String msg) {
        this.ret = ret;
        this.errorCode = errorCode;
        this.msg = msg;
    }

    public ResultDTO() {

    }

    private ResultDTO(Integer ret, Integer errorCode, String msg, Object data) {
        this(ret, errorCode, msg);
        this.data = data;
    }

    public static ResultDTO success() {
        return new ResultDTO(0, ResponseMsg.MSG_200, ResponseMsg.getMsg(ResponseMsg.MSG_200), "OK");
    }

    public static ResultDTO success(Object content) {
        return new ResultDTO(0, ResponseMsg.MSG_200, ResponseMsg.getMsg(ResponseMsg.MSG_200), content);
    }

    public static ResultDTO success(String msg, Object content) {
        return new ResultDTO(0, ResponseMsg.MSG_200, msg, content);
    }

    public static ResultDTO fail() {
        return new ResultDTO(1, ResponseMsg.MSG_500, ResponseMsg.getMsg(ResponseMsg.MSG_500), "");
    }

    public static ResultDTO fail(Object content) {
        return new ResultDTO(1, ResponseMsg.MSG_500, ResponseMsg.getMsg(ResponseMsg.MSG_500), content);
    }

    public static ResultDTO fail(Integer code, String msg) {
        return new ResultDTO(1, code, msg, "");
    }
    public static ResultDTO failMsg(String msg) {
        return new ResultDTO(1, ResponseMsg.MSG_500, msg, "");
    }

    public static ResultDTO fail(Integer code) {
        return new ResultDTO(1, code, ResponseMsg.getMsg(code), "");
    }

    public Integer getRet() {
        return ret;
    }

    public void setRet(Integer ret) {
        this.ret = ret;
    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
